home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / quickcom.arc / TERMQCOM.BAS < prev   
BASIC Source File  |  1989-06-09  |  3KB  |  87 lines

  1. DEFINT A-Z
  2.  
  3. DECLARE SUB Filter (InString$)
  4.  
  5. REM $INCLUDE: 'QUICKCOM.BI'      'Must have for function declarations
  6.  
  7. COLOR 7, 1                      ' Set screen color.
  8. CLS
  9.  
  10. Quit$ = CHR$(0) + CHR$(16)      ' Value returned by INKEY$
  11.                                 ' when ALT+q is pressed.
  12.  
  13. ' Set up prompt on bottom line of screen and turn cursor on:
  14. LOCATE 24, 1, 1
  15. PRINT STRING$(80, "_");
  16. LOCATE 25, 1
  17. PRINT TAB(30); "Press ALT+q to quit";
  18.  
  19. VIEW PRINT 1 TO 23              ' Print between lines 1 & 23.
  20.  
  21. ' Open communications (1200 baud, no parity, 8-bit data,
  22. ' 1 stop bit, 256-byte input buffer):
  23. 'OPEN "COM1:9600,N,8,1" FOR RANDOM AS #1 LEN = 256
  24. IF (QComInit("COM1:,9600,N,8,1,CTS")) THEN
  25.    PRINT "ERROR OPENING COM PORT!"
  26.    END
  27. END IF
  28.  
  29. DO                              ' Main communications loop.
  30.  
  31.    KeyInput$ = INKEY$           ' Check the keyboard.
  32.  
  33.    IF KeyInput$ = Quit$ THEN    ' Exit the loop if the user
  34.       EXIT DO                   ' pressed ALT+q.
  35.  
  36.    ELSEIF KeyInput$ <> "" THEN  ' Otherwise, if the user has
  37.      'PRINT #1, KeyInput$;      ' pressed a key, send the
  38.      ErCd = QComOut(KeyInput$)
  39.    END IF                       ' character typed to the modem.
  40.  
  41.    ' Check the modem. If characters are waiting (EOF(1) is
  42.    ' true), get them and print them to the screen:
  43.    ' IF NOT EOF(1) THEN
  44.    IF NOT QComEOF THEN
  45.  
  46.       ' LOC(1) gives the number of characters waiting:
  47.       ' ModemInput$ = INPUT$(LOC(1), #1)
  48.       ModemInput$ = QComInput$(ErCd)
  49.       IF ErCd = -3 THEN QComFlush
  50.  
  51.       Filter ModemInput$        ' Filter out line feeds and
  52.       PRINT ModemInput$;        ' backspaces, then print.
  53.    END IF
  54. LOOP
  55.  
  56. 'CLOSE                           ' End communications.
  57. QComClose
  58. CLS
  59. END
  60.  
  61. '
  62. ' ========================= FILTER ==========================
  63. '     Filters characters in an input string.
  64. ' ============================================================
  65. '
  66. SUB Filter (InString$) STATIC
  67.  
  68.    ' Look for backspace characters and recode them to
  69.    ' CHR$(29) (the LEFT cursor key):
  70.    DO
  71.       BackSpace = INSTR(InString$, CHR$(8))
  72.       IF BackSpace THEN
  73.          MID$(InString$, BackSpace) = CHR$(29)
  74.       END IF
  75.    LOOP WHILE BackSpace
  76.  
  77.    ' Look for line-feed characters and remove any found:
  78.    DO
  79.       LineFeed = INSTR(InString$, CHR$(10))
  80.       IF LineFeed THEN
  81.          InString$ = LEFT$(InString$, LineFeed - 1) + MID$(InString$, LineFeed + 1)
  82.       END IF
  83.    LOOP WHILE LineFeed
  84.  
  85. END SUB
  86.  
  87.